home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC 1.37.1r15 Full / Sources / driver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-20  |  21.1 KB  |  855 lines  |  [TEXT/MPS ]

  1. /*
  2.     driver program for mpw native gcc compiler
  3.     
  4.   Copyright (C) 1990, 1992 Apple Computer, Inc.
  5.     
  6.     Written by:
  7.         Larry Rosenstein
  8.         Brent H. Pease
  9.     
  10.     
  11.     Accepts most MPW C command line arguments and transforms them into gcc arguments.
  12.     Issues warnings for MPW C command arguments that are NOT supported
  13.     Accepts certain GCC C command arguments that do not conflict with MPW C
  14. */
  15.  
  16. #include <types.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #define MAXFILENAME 255
  22.  
  23. int    run_cpp = 1;
  24. int run_cc1 = 1;
  25. int run_asm = 1;
  26. int optimize = 1;
  27. int quiet_flag = 1;
  28. int echo_cmds = 0;
  29. int make_short = 0;
  30. int got_mc68020 = 0;
  31. int debug_gcc = 0;
  32. int overlay_strings = 0;
  33.  
  34. char* output_filename;
  35. char* input_filename;
  36. char* tool_place;
  37. char* tmp;
  38.  
  39. char *cpp_options;
  40. char *cc1_options;
  41. char *asm_options;
  42.  
  43. char *tool_suffix = "";
  44.  
  45. char tmp_filename[MAXFILENAME];
  46. char cpp_filename[MAXFILENAME];
  47. char asm_filename[MAXFILENAME];
  48. char out_filename[MAXFILENAME];
  49. char *shorten_filename = "•••asm_warnings•••";
  50. char *shorten_out_filename = "•••asm_modified•••";
  51.  
  52. /*Handle the sym options notypes, nolines, novars*/
  53. int HandleSymOpts(char *pOpt) {
  54.     register char *ptr = pOpt;
  55.     
  56.     while(1) {
  57.         /*Check for notypes*/
  58.         if (strncmp(ptr, "notypes", 7) == 0) {
  59.             warn_not_implemented("notypes");
  60.             ptr += 7;
  61.         
  62.         /*Check for nolines*/
  63.         } else if (strncmp(ptr, "nolines", 7) == 0) {
  64.             warn_not_implemented("nolines");
  65.             ptr += 7;
  66.         
  67.         /*Check for novars*/
  68.         } else if (strncmp(ptr, "novars", 6) == 0) {
  69.             warn_not_implemented("novars");
  70.             ptr += 6;
  71.         
  72.         /*Check for must not be a sym option*/
  73.         } else {
  74.             return 0;
  75.         }
  76.         if ((*ptr != ',') || (*ptr == 0)) {
  77.             return 1;
  78.         }
  79.         ptr++;
  80.     }
  81. }
  82.  
  83. /*Handle the -opt*/
  84. void HandleOptOpts(char *pOpt) {
  85.     register char *ptr = pOpt;
  86.     
  87.     while(1) {
  88.         /*Check for off(mpwc)*/
  89.         if (strncmp(ptr, "off", 3) == 0) {
  90.             optimize = 0;
  91.             ptr += 3;
  92.         
  93.         /*Check for on(mpwc)*/
  94.         } else if (strncmp(ptr, "on", 2) == 0) {
  95.             optimize = 1;
  96.             ptr += 2;
  97.         
  98.         /*Check for full(mpwc)*/
  99.         } else if (strncmp(ptr, "full", 4) == 0) {
  100.             optimize = 1;
  101.             make_short = 1;
  102.             ptr += 4;
  103.         
  104.         /*Check for nopeep(mpwc)*/
  105.         } else if (strncmp(ptr, "nopeep", 6) == 0) {
  106.             strcat(cc1_options, " -fno-peephole");
  107.             ptr += 6;
  108.         
  109.         /*Check for nocse(mpwc)*/
  110.         } else if (strncmp(ptr, "nocse", 5) == 0) {
  111.             warn_not_implemented("nocse");
  112.             ptr += 5;
  113.         
  114.         /*Check for high(custom)*/
  115.         } else if (strncmp(ptr, "high", 4) == 0) {
  116.             optimize = 2;
  117.             make_short = 1;
  118.             ptr += 4;
  119.         
  120.         /*Check for branch(custom)*/
  121.         } else if (strncmp(ptr, "branch", 6) == 0) {
  122.             make_short = 1;
  123.             ptr += 6;
  124.         
  125.         /*Unknown option*/
  126.         } else {
  127.             fprintf (stderr, "Warning: unknown option for -opt.\n");
  128.         }
  129.         if ((*ptr != ',') || (*ptr == 0)) {
  130.             return;
  131.         }
  132.         ptr++;
  133.     }
  134. }
  135.  
  136. main (argc, argv)
  137. int argc;
  138. char* argv[];
  139. {
  140.     int i, badopt;
  141.     char* arg, *arg1;
  142.     char* missing;
  143.     char* basename;
  144.     
  145.     cpp_options = (char *)malloc(10000);
  146.     cc1_options = (char *)malloc(10000);
  147.     asm_options = (char *)malloc(10000);
  148.     *cpp_options = 0;
  149.     *cc1_options = 0;
  150.     *asm_options = 0;
  151.     
  152.     output_filename = "";
  153.     input_filename = "";
  154.     tool_place = "";
  155.     tmp = ":";
  156.     
  157.     strcpy(cpp_options, "-D__GNUC__=1");
  158.     cc1_options[0] = '\0';
  159.     //strcpy(asm_options, "-w");
  160.     
  161.     for (i=1; i<argc; i++) {
  162.         arg = argv[i];
  163.         badopt = 0;
  164.         missing = "";
  165.         
  166.         if (arg[0] == '-') {
  167.           arg1 = arg;
  168.             switch(arg[1]) {
  169.                 case 'a':
  170.                     /*Check for -ansi(gcc)*/
  171.                     if (strcmp(arg, "-ansi") == 0) {
  172.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  173.                         
  174.                     /*Check for -asm(custom)*/
  175.                     } else if (strcmp(arg, "-asm") == 0) {
  176.                         run_asm = 0;
  177.                     
  178.                     /*Unknown option*/
  179.                     } else {
  180.                         badopt = 1;
  181.                     }
  182.                     break;
  183.                     
  184.                 case 'b':
  185.                     /*Check for -b(mpwc)*/
  186.                     if (arg[2] == '\0') {
  187.                         strcat(cc1_options, " -mbfun -mbstr");
  188.                     } else if ( arg[2] == '2' && arg[3] == '\0' ) {
  189.                         strcat(cc1_options, " -mbfun -mbstr");
  190.                         overlay_strings = 1;
  191.                     } else if ( arg[2] == '3' && arg[3] == '\0' ) {
  192.                         strcat(cc1_options, " -mbstr");
  193.                         overlay_strings = 1;
  194.                     } else if (strcmp(arg, "-bigseg") == 0) {
  195.                         warn_not_implemented(arg);
  196.                     
  197.                     /*Unknown option*/
  198.                     } else {
  199.                         badopt = 1;
  200.                     }
  201.                     break;
  202.                     
  203.                 case 'c':
  204.                     /*Check for -c(mpwc)*/
  205.                     if (arg[2] == '\0') {
  206.                         run_cc1 = 0;
  207.                     
  208.                     /*Unknown option*/
  209.                     } else {
  210.                         badopt = 1;
  211.                     }
  212.                     break;
  213.                     
  214.                 case 'd':
  215.                     /*Check for -d string(mpwc)*/
  216.                     if (arg[2] == '\0') {
  217.                         if (++i<argc) {
  218.                             char *savepos = cpp_options+strlen(cpp_options);
  219.                             /*transform into gcc command*/
  220.                             strcat(cpp_options, " -D");  strcat(cpp_options, argv[i]);
  221.                             escape_single_quotes(savepos);
  222.                         } else {
  223.                             missing = "symbol";
  224.                         }
  225.                                         
  226.                     } else {
  227.                         /* Probably a debugging option -d<x> - pass thru to cc1 */
  228.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  229.                     }
  230.                     break;
  231.                     
  232.                 case 'e':
  233.                     /*Check for -e(mpwc)*/
  234.                     if (arg[2] == '\0') {
  235.                         /*Transform into gcc argument*/
  236.                         strcat(cpp_options, " -C");
  237.                         run_cc1 = 0;
  238.                     
  239.                     /*Check for -e2(mpwc)*/
  240.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  241.                         run_cc1 = 0;
  242.                     
  243.                     /*Check for -elems881(mpwc)*/
  244.                     } else if (strcmp(arg, "-elems881") == 0) {
  245.                         strcat(cc1_options, " -melems881");
  246.                     
  247.                     /*Unknown option*/
  248.                     } else {
  249.                         badopt = 1;
  250.                     }
  251.                     break;
  252.                     
  253.                 case 'f':
  254.                     /*Check for fx(undocumented)*/
  255.                     if (arg[2] == 'x' && arg[3] == '\0') {
  256.                         /*Make sure there is another option*/
  257.                         if (++i>=argc) {
  258.                             missing = "number";
  259.                         
  260.                         /*Check for 30*/
  261.                         } else if (strcmp(argv[i], "30") == 0) {
  262.                             strcat(cc1_options, " -mfx30");
  263.                         
  264.                         /*Unknown fx argument*/
  265.                         } else {
  266.                             fprintf (stderr, "Warning: -fx %s ignored.\n", argv[i]);
  267.                         }
  268.                     
  269.                     /*Check for a whole slew of gcc options*/
  270.                     } else if (arg[2] != '\0') {
  271.                         /* pass it on to cc1 and let it complain */
  272.                         strcat(cc1_options, " ");
  273.                         strcat(cc1_options, arg);
  274.                     
  275.                     /*Unknown option*/
  276.                     } else {
  277.                         badopt = 1;
  278.                     }
  279.                     break;
  280.                 
  281.                 case 'i':
  282.                     /*check for -i pathname(mpwc)*/
  283.                     if (arg[2] == '\0') {
  284.                         /*Make sure there are more arguments*/
  285.                         if (++i<argc) {
  286.                             /*Transform into gcc argument*/
  287.                             strcat(cpp_options, " -I'");
  288.                             strcat(cpp_options, argv[i]);
  289.                             strcat(cpp_options, "'");
  290.                         } else {
  291.                             missing = "directory";
  292.                         }
  293.                     } else {
  294.                         badopt = 1;
  295.                     }
  296.                     break;
  297.                 
  298.                 case 'k':
  299.                     /* check for -k (MPW C) */
  300.                     if (arg[2] == '/0')
  301.                     {
  302.                         warn_not_implemented(arg);
  303.                         if (argv[i+1] != '-')    /* directory name to go along with -k */
  304.                             i++;
  305.                     }
  306.                             
  307.                     /* check for -kon (equiv to -opt branch) */
  308.                     else if (strcmp(arg, "-kon") == 0)
  309.                         make_short = 1;
  310.                     else
  311.                         badopt = 1;
  312.                         break;
  313.                 
  314.                 case 'm':
  315.                     /*Check for -m(mpwc)*/
  316.                     if (arg[2] == '\0') {
  317.                         /*Translate into gcc lingo*/
  318.                         strcat(cc1_options, " -mm");
  319.                         if (got_mc68020 == 0) {
  320.                             /*Make sure the user knows whats up*/
  321.                             fprintf (stderr, "Warning: -m forces -mc68020\n");
  322.                             strcat(cpp_options, " -Dmc68020");
  323.                             strcat(cc1_options, " -m68020");
  324.                             got_mc68020 = 1;
  325.                         }
  326.                     
  327.                     /*Check for makedep(custom)*/
  328.                     } else if (strcmp(arg, "-makedep") == 0) {
  329.                         /*Translate*/
  330.                         strcat(cpp_options, " -M");
  331.                         run_cc1 = 0;
  332.                     
  333.                     /*Check for -mbg(mpwc)*/
  334.                     } else if (strcmp(arg, "-mbg") == 0) {
  335.                         /*Make sure there is another argument*/
  336.                         if (++i<argc) {
  337.                             
  338.                             /*Check for off*/
  339.                             if (strcmp(argv[i], "off") == 0) {
  340.                                 strcat(cc1_options, " -mbgoff -fomit-frame-pointer");
  341.                             
  342.                             /*Check for full*/
  343.                             } else if (strcmp(argv[i], "full") == 0) {
  344.                                 /*Default*/
  345.                                 
  346.                             /*Check for on*/
  347.                             } else if (strcmp(argv[i], "on") == 0) {
  348.                                 fprintf (stderr, "Warning: -mbg on is not supported, try -mbg full.\n");
  349.                             
  350.                             /*Unknown option*/
  351.                             } else {
  352.                                 missing = "on|full";
  353.                             }
  354.                         } else {
  355.                             missing = "on|full";
  356.                         }
  357.                     
  358.                     /*Check for -mc68020(mpwc)*/
  359.                     } else if (strcmp(arg, "-mc68020") == 0) {
  360.                         /*Add in options if needed*/
  361.                         if (got_mc68020 == 0) {
  362.                             strcat(cpp_options, " -Dmc68020");
  363.                             strcat(cc1_options, " -m68020");
  364.                             got_mc68020 = 1;
  365.                         }
  366.                     
  367.                     /*Check for -mc68881(mpwc)*/
  368.                     } else if (strcmp(arg, "-mc68881") == 0) {
  369.                         strcat(cpp_options, " -Dmc68881");
  370.                         strcat(cc1_options, " -m68881");
  371.                     
  372.                     /*Check for -mnoseg(custom)*/
  373.                     } else if (strcmp(arg, "-mnoseg") == 0) {
  374.                         strcat(cc1_options, " -mnoseg");
  375.                     
  376.                     /*Check for -model(mpwc)*/
  377.                     } else if (strcmp(arg, "-model") == 0) {
  378.                         if (++i < argc) {
  379.                             /* get the next arg */
  380.                             arg = argv[i];
  381.                             /*Check for near*/
  382.                             if (strcmp(arg, "near") == 0) {
  383.                                 warn_not_implemented("-model near");
  384.                             
  385.                             /*Check for far*/
  386.                             } else if (strcmp(arg, "far") == 0) {
  387.                                 warn_not_implemented("-model far");
  388.                             
  389.                             /*Check for nearData*/
  390.                             } else if (strcmp(arg, "nearData") == 0) {
  391.                                 warn_not_implemented("-model nearData");
  392.                             
  393.                             /*Check for farData*/
  394.                             } else if (strcmp(arg, "farData") == 0) {
  395.                                 warn_not_implemented("-model farData");
  396.                             
  397.                             /*Check for nearCode*/
  398.                             } else if (strcmp(arg, "nearCode") == 0) {
  399.                                 warn_not_implemented("-model nearCode");
  400.                             
  401.                             /*Check for farCode*/
  402.                             } else if (strcmp(arg, "farCode") == 0) {
  403.                                 warn_not_implemented("-model farCode");
  404.                             
  405.                             /*Unknown options*/
  406.                             } else {
  407.                                 missing = "near|far|nearData|farData|nearCode|farCode";
  408.                             }
  409.                             
  410.                         /*Unknown option*/
  411.                         } else {
  412.                             missing = "near|far|nearData|farData|nearCode|farCode";
  413.                         }
  414.                   } else {
  415.                         /* pass it on to cc1 and let it analyze */
  416.                         strcat(cc1_options, " ");
  417.                         strcat(cc1_options, arg);
  418.                     }
  419.                     break;
  420.                     
  421.                 case 'n':
  422.                     if (!strcmp(arg, "-noext")) {
  423.                         tool_suffix = "";
  424.  
  425.                     } else if (!strcmp(arg, "-nocpp")) {
  426.                         run_cpp = 0;
  427.  
  428.                     /*Check for -n(mpwc)*/
  429.                     } else if (arg[2] == '\0') {
  430.                         /* This is the default for GCC, so can ignore. */
  431.                     /*Unknown option*/
  432.                     } else {
  433.                         badopt = 1;
  434.                     }
  435.                     break;
  436.                     
  437.                 case 'o':
  438.                     /*Check for -opt(mpwc)*/
  439.                     if (strcmp(arg, "-opt") == 0) {
  440.                         /*Make sure we have enough arguments left*/
  441.                         if (++i<argc) {
  442.                             HandleOptOpts(argv[i]);
  443.                         
  444.                         /*Not enough arguments*/
  445.                         } else {
  446.                             missing = "on|off|full";
  447.                         }
  448.                     
  449.                     /*Check for -o objname(mpwc)*/
  450.                     } else if (arg[2] == '\0') {
  451.                         /*Make sure we have enough arguments*/
  452.                         if (++i<argc) {
  453.                             output_filename = argv[i];
  454.                         
  455.                         /*Not enough arguments*/
  456.                         } else {
  457.                             missing = "output filename";
  458.                         }
  459.                     
  460.                     /*Unknown option*/
  461.                     } else {
  462.                         badopt = 1;
  463.                     }
  464.                     break;
  465.     
  466.                 case 'p':
  467.                     /*Check for -p(mpwc)*/
  468.                     if (arg[2] == '\0') {
  469.                         /*Translate into gcc args*/
  470.                         strcat(cpp_options, " -v");
  471.                         strcat(cc1_options, " -version");
  472.                         quiet_flag = 0;
  473.                         strcat(asm_options, " -p");
  474.                         echo_cmds = 1;
  475.                     
  476.                     /*Check for -pedantic(gcc)*/
  477.                     } else if (strcmp(arg, "-pedantic") == 0) {
  478.                         strcat(cpp_options, " -pedantic");
  479.                         strcat(cc1_options, " -pedantic");
  480.                     
  481.                     /*Unkown option*/
  482.                     } else {
  483.                         badopt = 1;
  484.                     }
  485.                     break;
  486.                     
  487.                 case 'r':
  488.                     /*Check for -r(mpwc)*/
  489.                     if (arg[2] == '\0') {
  490.                         strcat(cc1_options, " -Wimplicit");
  491.                     
  492.                     /*Unkown*/
  493.                     } else {
  494.                         badopt = 1;
  495.                     }
  496.                     break;
  497.                     
  498.                 case 's':
  499.                     /*check for -s segment(mpwc)*/
  500.                     if (arg[2] == '\0') {
  501.                         /*Make sure we have enough options*/
  502.                         if (++i<argc) {
  503.                             strcat(cc1_options, " -s '");
  504.                             strcat(cc1_options, argv[i]);
  505.                             strcat(cc1_options, "'");
  506.                         } else {
  507.                             missing = "segment name";
  508.                         }
  509.                     }
  510.                     
  511.                     /*Check for -sym(mpwc)*/
  512.                     else if (strcmp(arg, "-sym") == 0) {
  513.                         /*Make sure we have enough args*/
  514.                         if (++i<argc) {
  515.                             if ((strcmp(argv[i], "full") == 0) || (strcmp(argv[i], "on") == 0)) {
  516.                                 if (HandleSymOpts(argv[i+1])) {
  517.                                     i++;
  518.                                 }
  519.                                 strcat(asm_options, " -sym ");  strcat(asm_options, argv[i]);
  520.                                 fprintf (stderr, "Warning: symbolic info will be produced by assembler.\n");
  521.                             } else if (strcmp(argv[i], "off") == 0) {
  522.                                 /*default*/
  523.                             } else {
  524.                                 missing = "on|off|full";
  525.                             }
  526.                         } else {
  527.                             missing = "option";
  528.                         }
  529.                     
  530.                     /*Unknown option*/
  531.                     } else {
  532.                         badopt = 1;
  533.                     }
  534.                     break;
  535.                     
  536.                 case 't':
  537.                     /*Check for -t(mpwc)*/
  538.                     if (arg[2] == '\0') {
  539.                         quiet_flag = 0;
  540.                         strcat(asm_options, " -t");
  541.                     
  542.                     /*Check for -traditional(gcc)*/
  543.                     } else if (strcmp(arg, "-traditional") == 0) {
  544.                         strcat(cpp_options, " -traditional");
  545.                         strcat(cc1_options, " -traditional");
  546.                         
  547.                     /*Check for tools(custom)*/
  548.                     } else if (strcmp(arg, "-tools") == 0) {
  549.                         /*Make sure there are enough args*/
  550.                         if (++i<argc) {
  551.                             tool_place = argv[i];
  552.                         } else {
  553.                             missing = "directory";
  554.                         }
  555.                     
  556.                     /*Check for -trace(mpwc)*/
  557.                     } else if (strcmp(arg, "-trace") == 0) {
  558.                         /*Make sure there are enough args*/
  559.                         if (++i<argc) {
  560.                             /*Check for on*/
  561.                             if (strcmp(argv[i], "on") == 0) {
  562.                                 strcat(cc1_options, " -trace on");
  563.                             
  564.                             /*Check for off*/
  565.                             } else if (strcmp(argv[i], "off") == 0) {
  566.                                 strcat(cc1_options, " -trace off");
  567.                             
  568.                             /*Check for always*/
  569.                             } else if (strcmp(argv[i], "always") == 0) {
  570.                                 strcat(cc1_options, " -trace always");
  571.                             
  572.                             /*Check for never*/
  573.                             } else if (strcmp(argv[i], "never") == 0) {
  574.                                 strcat(cc1_options, " -trace never");
  575.                             
  576.                             /*Unknown option*/
  577.                             } else {
  578.                                 missing = "on|off|always|never";
  579.                             }
  580.                         
  581.                         /*Unknown option*/
  582.                         } else {
  583.                             missing = "on|off|always|never";
  584.                         }
  585.                     
  586.                     /*Unknown option*/
  587.                     } else {
  588.                         badopt = 1;
  589.                     }
  590.                     break;
  591.                 
  592.                 case 'u':
  593.                     /*check for -u(mpwc)*/
  594.                     if (arg[2] == '\0') {
  595.                         /*Make sure there are enough args*/
  596.                         if (++i<argc) {
  597.                             /*Translate into gcc*/
  598.                             strcat(cpp_options, " -U");  strcat(cpp_options, argv[i]);
  599.                         
  600.                         /*Not enough args*/
  601.                         } else {
  602.                             missing = "symbol";
  603.                         }
  604.                         
  605.                     /*Unknown option*/
  606.                     } else {
  607.                         badopt = 1;
  608.                     }
  609.                     break;
  610.                     
  611.                 case 'w':
  612.                     /*Check for -w(mpwc)*/
  613.                     if (arg[2] == '\0') {
  614.                         strcat(cc1_options, " -w");
  615.                     
  616.                     /*Check for -w2(mpwc)*/
  617.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  618.                         strcat(cc1_options, " -Wall");
  619.                     
  620.                     /*Check for -warnings(mpwc)*/
  621.                     } else if (strcmp(arg, "-warnings") == 0) {
  622.                         /*Make sure there are enough args*/
  623.                         if (++i<argc) {
  624.                             
  625.                             /*Check for on*/
  626.                             if (strcmp(argv[i], "on") == 0) {
  627.                                 strcat(cc1_options, " -Wall");
  628.                             
  629.                             /*Check for full*/
  630.                             } else if (strcmp(argv[i], "full") == 0) {
  631.                                 strcat(cc1_options, " -Wall");
  632.                             
  633.                             /*Check for off*/
  634.                             } else if (strcmp(argv[i], "off") == 0) {
  635.                                 strcat(cc1_options, " -w");
  636.                             
  637.                             /*Unknown option*/
  638.                             } else {
  639.                                 missing = "on|off|full";
  640.                             }
  641.  
  642.                         /*Unknown option*/
  643.                         } else {
  644.                             missing = "on|off|full";
  645.                         }
  646.                     
  647.                     /*Unknown option*/
  648.                     } else {
  649.                         badopt = 1;
  650.                     }
  651.                     break;
  652.                 
  653.                 case 'W':
  654.                     /*Check for -W(gcc)*/
  655.                     if (arg[2] == '\0') {
  656.                         strcat(cc1_options, " -W");
  657.                     
  658.                     /*Check for -Wall(gcc)*/
  659.                     } else if (strcmp(arg, "-Wall") == 0) {
  660.                         strcat(cc1_options, " -Wall");
  661.                     
  662.                     /*Check for a slew of gcc options*/
  663.                     } else if (arg[2] != '\0') {
  664.                         /* pass it to cc1 and let it complain */
  665.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  666.                     } else {
  667.                         badopt = 1;
  668.                     }
  669.                     break;
  670.                     
  671.                 case 'y':
  672.                     /*Check for -y(mpwc)*/
  673.                     if (arg[2] == '\0') {
  674.                         if (++i<argc) {
  675.                             tmp = arg;
  676.                         } else {
  677.                             missing = "directory";
  678.                         }
  679.                     } else {
  680.                         badopt = 1;
  681.                     }
  682.                     break;
  683.     
  684.                 default:
  685.                     badopt = 1;
  686.             }
  687.             
  688.             if (missing[0] != '\0') {
  689.                 fprintf (stderr, "Warning: missing %s after \"%s\".\n", missing, arg1);
  690.             } else if (badopt) {
  691.                 fprintf (stderr, "Warning: invalid option %s ignored.\n", arg);
  692.             }
  693.         
  694.         /*Check for filename*/
  695.         } else if (input_filename[0] == '\0') {
  696.             input_filename = arg;
  697.         
  698.         /*Extra file names is a no no*/
  699.         } else {
  700.             fprintf (stderr, "Warning: extra input filename %s ignored.\n", arg);
  701.         }
  702.     }
  703.     
  704.     /*Not enough filenames is a no no*/
  705.     if (input_filename[0] == '\0') {
  706.         fprintf (stderr, "Error: no input filename.\n");
  707.         exit(2);
  708.     }
  709.     
  710.     strcpy(tmp_filename, tmp);
  711.     if ( (basename = strrchr(input_filename, ':')) != NULL)
  712.         ++basename;
  713.     else
  714.       basename = input_filename;
  715.     strcat(tmp_filename, basename);
  716.     
  717.     if (run_cc1) {
  718.         strcpy(cpp_filename, tmp_filename);
  719.         strcat(cpp_filename, "._");
  720.     }
  721.     
  722.     strcpy(asm_filename, tmp_filename);
  723.     strcat(asm_filename, ".a");
  724.     
  725.     if (output_filename[0] == '\0') {
  726.         strcpy(out_filename, input_filename);
  727.         strcat(out_filename, ".o");
  728.         output_filename = out_filename;
  729.     }
  730.     else if (output_filename[strlen(output_filename)-1] == ':') { // it's a directory, copy basename so we get .c.o 
  731.         strcpy(out_filename, output_filename);                                          // not .c.a.o
  732.         strcat(out_filename, basename);                                                            
  733.         strcat(out_filename, ".o");
  734.         output_filename = out_filename;
  735.     }
  736.         
  737.     if (quiet_flag)
  738.         strcat(cc1_options, " -quiet");
  739.         
  740.     if (optimize)
  741.         strcat(cc1_options, " -O");
  742.     else if (optimize >= 2)
  743.         strcat(cc1_options, " -O2");
  744.         
  745.     printf ("set oldexit {exit}\n");
  746.     printf ("set exit 0\n");
  747.             
  748.     if (run_cpp) {
  749.         if (echo_cmds)
  750.             printf ("\techo \"'%s'cpp%s %s '%s' '%s'\"\n", tool_place, tool_suffix, cpp_options, input_filename, cpp_filename);
  751.         printf (           "'%s'cpp%s %s '%s' '%s'\n",   tool_place, tool_suffix, cpp_options, input_filename, cpp_filename);
  752.         printf ("if {status} == 0\n");
  753.     }
  754.         
  755.     if (run_cc1) {
  756.         if (echo_cmds)
  757.             printf ("\techo \"'%s'cc1%s %s '%s' -o '%s' -dumpbase '%s'\"\n", tool_place, tool_suffix, cc1_options, cpp_filename, asm_filename, tmp_filename);
  758.         printf (         "\t'%s'cc1%s %s '%s' -o '%s' -dumpbase '%s'\n",   tool_place, tool_suffix, cc1_options, cpp_filename, asm_filename, tmp_filename);
  759.         printf ("\tif {status} == 0\n");
  760.         if (!debug_gcc && run_cpp) {
  761.             printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  762.         }
  763.         
  764.         if (run_asm) {
  765.             if (make_short) {
  766.                 if (echo_cmds)
  767.                     printf ("\t\techo \"asm %s '%s' -o '%s' ∑ '%s'\"\n", asm_options, asm_filename, output_filename, shorten_filename);
  768.                 printf ("\t\techo -n > '%s'\n", shorten_filename);
  769.                 printf (         "\t\tasm %s '%s' -o '%s' ∑ '%s'\n",   asm_options, asm_filename, output_filename, shorten_filename);
  770.                 printf ("\t\tloop\n");
  771.                 if (echo_cmds)
  772.                   printf ("\t\t\techo \"Search -sf /•### Warning 210/ '%s' >> dev:null\"\n", shorten_filename);
  773.                 printf (         "\t\t\tSearch -sf /•### Warning 210/ '%s' >> dev:null\n",   shorten_filename);
  774.                 printf ("\t\t\tif {status} == 0\n");
  775.                 if (echo_cmds)
  776.                     printf ("\t\t\t\techo \"'%s'shorten -a '%s' -e '%s' -o '%s'\"\n", tool_place, asm_filename, shorten_filename, shorten_out_filename);
  777.                 printf (         "\t\t\t\t'%s'shorten -a '%s' -e '%s' -o '%s'\n",   tool_place, asm_filename, shorten_filename, shorten_out_filename);
  778.                 if (echo_cmds)
  779.                   printf ("\t\t\t\techo \"move -y '%s' '%s'\"\n", shorten_out_filename, asm_filename);
  780.                 printf (         "\t\t\t\tmove -y '%s' '%s'\n",   shorten_out_filename, asm_filename);
  781.                 if (echo_cmds)
  782.                     printf ("\t\t\t\techo \"asm %s '%s' -o '%s' ∑ '%s'\"\n", asm_options, asm_filename, output_filename, shorten_filename);
  783.                 printf (         "\t\t\t\tasm %s '%s' -o '%s' ∑ '%s'\n",   asm_options, asm_filename, output_filename, shorten_filename);
  784.                 printf ("\t\t\telse\n");
  785.                 if (!debug_gcc)
  786.                 {
  787.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_filename);
  788.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_out_filename);
  789.                 }
  790.                 printf ("\t\t\t\tbreak\n");
  791.                 printf ("\t\t\tend\n");
  792.                 printf ("\t\tend\n");
  793.             }
  794.             else
  795.             {
  796.                 if (echo_cmds)
  797.                     printf ("\t\techo \"asm -w %s '%s' -o '%s'\"\n", asm_options, asm_filename, output_filename);
  798.                 printf (         "\t\tasm -w %s '%s' -o '%s'\n",   asm_options, asm_filename, output_filename);
  799.             }
  800.             printf ("\t\tif {status} == 0\n");
  801.             if (!debug_gcc)
  802.                 printf ("\t\t\tdelete -i -y '%s'\n", asm_filename);
  803.             printf ("\t\telse\n");
  804.             printf ("\t\t\tset exit {oldexit}\n");
  805.             printf ("\t\t\texit 2\n");
  806.             printf ("\t\tend\n");
  807.         }
  808.         printf ("\telse\n");
  809.         if (!debug_gcc) {
  810.             if (run_cpp)
  811.                 printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  812.             printf ("\t\tdelete -i -y '%s'\n", asm_filename);
  813.         }
  814.         printf ("\t\tset exit {oldexit}\n");
  815.         printf ("\t\texit 2\n");
  816.         printf ("\tend\n");
  817.         
  818.     }
  819.     printf ("else\n");
  820.     if (!debug_gcc) {
  821.         printf ("\tdelete -i -y '%s'\n", cpp_filename);
  822.     }
  823.     printf ("\tset exit {oldexit}\n");
  824.     printf ("\texit 2\n");
  825.     printf ("end\n");
  826.     
  827. /*    if (echo_cmds)*/
  828. /*        printf ("set echo {oldecho}\n");*/
  829.     printf ("set exit {oldexit}\n");
  830.     
  831.     exit(0);
  832. }
  833.  
  834. warn_not_implemented(arg)
  835. char *arg;
  836. {
  837.   fprintf (stderr, "Warning: %s ignored, not implemented yet.\n", arg);
  838. }
  839.  
  840. escape_single_quotes(buf)
  841. char *buf;
  842. {
  843.     int i, j;
  844.     
  845.     for (i = 0; buf[i] != '\0'; ++i) {
  846.         if (buf[i] == '\'') {
  847.           buf[strlen(buf)+1] = '\0';
  848.             for (j = strlen(buf)+1; j > i; --j) {
  849.                 buf[j] = buf[j-1];
  850.           }
  851.           buf[i++] = '∂';
  852.         }
  853.     }
  854. }
  855.